package com.spark.mooc.ch2_scala.part02_objectOrientedProgramming

/**
 * @description:
 * @time: 2020/11/24 17:22
 * @author: lhy
 */

/**
 *case类：系统自动生成apply方法
 */
case class Book(val name:String,val price:Double)


object TestOption {
    def main(args: Array[String]): Unit = {
        //定义一个书名到书对象的映射
        val books = Map("hadoop" -> Book("Hadoop",35.5),
                       "com/spark" -> Book("Spark",55.5),
                        "hBase" -> Book("HBase",45.5))
        println(books.get("hadoop"))        //返回该键对应值的Some对象
        println(books.get("hive"))          //不存在该键，返回None对象
        val Book(hadoop_name,hadoop_price) = books("hadoop")
        println("hadoop_name:"+hadoop_name+"\thadoop_price:"+hadoop_price)
        val Book(hive_name,hive_price) = books.getOrElse("hive", Book("Unknown", 0))
        println("hive_name:"+hive_name+"\thive_price:"+hive_price)
    }
}
